<template>
  <view class="container">
    <button @click="add">新增 丁元英,40</button>
    <button @click="del">删除 丁元英</button>
    <button @click="update">更新 丁元英 → 50岁</button>
    <button @click="queryOne">查询 张三</button>
    <button @click="queryAll">查询所有</button>
	
	
	
  </view>
</template>

<script>
export default {
  methods: {
    call(action, data = {}) {
      uniCloud.callFunction({
        name: 'renyuan-crud',
        data: { action, ...data }
      }).then(res => {
        const result = res.result;
        if (result.code === 0) {
          console.log('成功:', result);
          uni.showToast({ title: '成功' });
        } else {
          console.error('失败:', result);
          uni.showModal({ content: result.msg || result.error, showCancel: false });
        }
      }).catch(err => {
        console.error('调用失败:', err);
        uni.showModal({ content: '网络错误', showCancel: false });
      });
    },

    add() {
      this.call('add', { name: '丁元英', age: 40 });
    },
    del() {
      this.call('delete', { name: '丁元英' });
    },
    update() {
      this.call('update', { name: '丁元英', age: 50 });
    },
    queryOne() {
      this.call('get', { name: '张三' });
    },
    queryAll() {
      this.call('get');
    }
  }
}
</script>

<style>
button { margin: 10px; }
</style>